var app = getApp();

Page({
    data: {
        navH: app.globalData.navHeight,
        show: 0,
        imgPath: app.getImgUrl(),
        linkData: !1
    },
    navBack: function() {
        app.globalData.from_act ? app.goIndex() : wx.navigateBack();
    },
    toIndex: function() {
        wx.switchTab({
            url: "../index/index"
        });
    },
    switchShow: function(a) {
        a = a.currentTarget.dataset.show, this.setData({
            show: a
        }), wx.pageScrollTo({
            scrollTop: 0,
            duration: 0
        });
    },
    onLoad: function(a) {
        this.setData({
            show: a.show
        }), this.getMtLink();
    },
    toMtwm: function() {
        var t;
        app.globalData.userInfo ? this.data.linkData ? wx.navigateToMiniProgram({
            appId: this.data.linkData.appid,
            path: this.data.linkData.mtwm.page_path,
            envVersion: "release",
            success: function(a) {
                console.log("打开小程序成功");
            }
        }) : (t = this, app.util.request({
            url: "entry/wxapp/getMtLink",
            success: function(a) {
                a = a.data.data, t.setData({
                    linkData: a
                }), wx.navigateToMiniProgram({
                    appId: t.data.linkData.appid,
                    path: t.data.linkData.mtwm.page_path,
                    envVersion: "release",
                    success: function(a) {
                        console.log("打开小程序成功");
                    }
                });
            }
        })) : app.checkLogin();
    },
    toMtsg: function() {
        var t;
        app.globalData.userInfo ? this.data.linkData ? wx.navigateToMiniProgram({
            appId: this.data.linkData.appid,
            path: this.data.linkData.mtsg.page_path,
            envVersion: "release",
            success: function(a) {
                console.log("打开小程序成功");
            }
        }) : (t = this, app.util.request({
            url: "entry/wxapp/getMtLink",
            success: function(a) {
                a = a.data.data, t.setData({
                    linkData: a
                }), wx.navigateToMiniProgram({
                    appId: t.data.linkData.appid,
                    path: t.data.linkData.mtsg.page_path,
                    envVersion: "release",
                    success: function(a) {
                        console.log("打开小程序成功");
                    }
                });
            }
        })) : app.checkLogin();
    },
    getMtLink: function() {
        var t;
        app.globalData.userInfo && (t = this, app.util.request({
            url: "entry/wxapp/getMtLink",
            success: function(a) {
                a = a.data.data, t.setData({
                    linkData: a
                });
            }
        }));
    },
    copyArt: function() {
        var t;
        app.globalData.userInfo ? this.data.linkData ? wx.setClipboardData({
            data: (1 == this.data.show ? this.data.linkData.mtsg : this.data.linkData.mtwm).guide_article,
            success: function(a) {
                app.globalData.showSmart = !1, wx.showToast({
                    title: "复制成功"
                });
            }
        }) : (t = this, app.util.request({
            url: "entry/wxapp/getMtLink",
            success: function(a) {
                a = a.data.data, t.setData({
                    linkData: a
                }), wx.setClipboardData({
                    data: (1 == t.data.show ? t.data.linkData.mtsg : t.data.linkData.mtwm).guide_article,
                    success: function(a) {
                        app.globalData.showSmart = !1, wx.showToast({
                            title: "复制成功"
                        });
                    }
                });
            }
        })) : app.checkLogin();
    },
    saveMtPoster: function() {
        var t;
        app.globalData.userInfo ? (t = this, app.util.request({
            url: "entry/wxapp/getMtPoster",
            data: {
                show: t.data.show,
                surl: (1 == t.data.show ? t.data.linkData.mtsg : t.data.linkData.mtwm).short_url
            },
            success: function(a) {
                a = a.data.data, console.log(a), wx.getImageInfo({
                    src: a,
                    success: function(a) {
                        wx.saveImageToPhotosAlbum({
                            filePath: a.path,
                            success: function(a) {
                                wx.showToast({
                                    title: "已保存至相册",
                                    icon: "success"
                                });
                            },
                            fail: function(a) {
                                console.log(a), wx.showModal({
                                    title: "系统提示",
                                    content: "请转至“授权设置”页面打开“保存到相册”开关",
                                    confirmColor: "#f43f6c",
                                    confirmText: "去打开",
                                    showCancel: !1,
                                    success: function(a) {
                                        wx.openSetting({
                                            withSubscriptions: !0,
                                            success: function() {}
                                        });
                                    }
                                });
                            }
                        });
                    },
                    complete: function() {
                        t.delPoster();
                    }
                });
            }
        })) : app.checkLogin();
    },
    delPoster: function() {
        app.util.request({
            url: "entry/wxapp/delTempPoster",
            showLoading: !1,
            success: function(a) {
                console.log(a);
            }
        });
    },
    onReady: function() {},
    onShow: function() {
        app.reUserInfo();
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    loginAfter: function(a) {
        app.loginAfter(a);
    },
    loginCancel: function() {
        app.loginCancel();
    },
    onShareTimeline: function() {
        var a = this, t = void 0 !== app.globalData.userInfo.uid ? "&from_uid=" + app.globalData.userInfo.uid + "&from_act=share" : "&from_act=share";
        return {
            title: 1 == a.data.show ? "【美团闪购34元红包】每日限时抢" : "【美团外卖65元红包】每日限时抢",
            imageUrl: 1 == a.data.show ? a.data.imgPath + "mtwm-main-st2.png" : a.data.imgPath + "mtwm-main-st.png",
            query: "show=" + a.data.show + t
        };
    },
    onShareAppMessage: function() {
        var a = this, t = 1 == a.data.show ? "【美团闪购34元红包】每日限时抢" : "【美团外卖65元红包】每日限时抢", n = 1 == a.data.show ? a.data.imgPath + "mtwm-main-st2.png" : a.data.imgPath + "mtwm-main-st.png", o = void 0 !== app.globalData.userInfo.uid ? "&from_uid=" + app.globalData.userInfo.uid + "&from_act=share" : "&from_act=share";
        return {
            title: t,
            path: "/first_duoduoke/pages/pleasure/pleasure-main?show=" + a.data.show + o,
            imageUrl: n,
            success: function(a) {
                "shareAppMessage:ok" == a.errMsg ? wx.showToast({
                    title: "分享成功",
                    icon: "success"
                }) : wx.showToast({
                    title: "分享失败",
                    icon: "none"
                });
            },
            fail: function(a) {
                "shareAppMessage:fail cancel" == a.errMsg || a.errMsg, wx.showToast({
                    title: "分享失败",
                    icon: "none"
                });
            }
        };
    }
});